/** @format */

import babel from 'rollup-plugin-babel';
import serve from 'rollup-plugin-serve';
import { eslint } from 'rollup-plugin-eslint';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';

export default {
  input: './src/index.js', // 以哪个文件作为打包的入口
  output: {
    file: 'dist/umd/vue.js', // 出口路径
    name: 'Vue', // 指定打包后全局变量的名字
    format: 'umd', // 统一模块规范
    sourcemap: true, // es6-> es5  开启源码调试 可以找到源代码的报错位置
  },
  // Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
  external: [],
  watch: {
    include: 'src/**',
  },
  plugins: [
    // 使用的插件
    babel({
      exclude: 'node_modules/**',
    }),
    // Allow json resolution
    json(),
    // Allow bundling cjs modules (unlike webpack, rollup doesn't understand cjs)
    commonjs(),
    // Allow node_modules resolution, so you can use 'external' to control
    // which external modules to include in the bundle
    // https://github.com/rollup/rollup-plugin-node-resolve#usage
    resolve(),
    eslint(),
    process.env.ENV === 'development'
      ? serve({
          open: true,
          openPage: '/public/index.html', // 默认打开html的路径
          port: 3000,
          contentBase: '',
        })
      : null,
  ],
};
